<?php namespace Home\Model;
use Hdphp\Model\Model;

class Category extends Model{
	protected $table="category";
	
	public function look($cid){
		$data = $this->get();
		$cids = $this->getSon($data,$cid);
		$cids[] = $cid;
		$cids = implode(',', $cids);
		$goods = new \Common\Model\Goods;
		$goodsData = $goods->where("category_cid IN ({$cids})")->get();
		return $goodsData;
	}
	
	public function getSon($data,$cid){
		$temp = array();
		foreach ($data as $k => $v) {
			if($v['pid'] == $cid){
				$temp[] = $v['cid'];
				$temp = array_merge($temp,$this->getSon($data,$v['cid']));
			}
		}
		return $temp;
	}
}

 ?>